<template>
	<view class="flexview">
		<view class="uni-list">
			<view class="uni-list-cell" v-for="(item,index) in list" :key="index">
				<view @click="toView(item)" class="uni-list-cell-navigate uni-navigate-right activity">
					<text>{{item.title}}</text>
					<text class="time">{{item.createtm}}</text>
				</view>
			</view>
			<view v-if="list.length==0" class="nodata">
				<image src="../../../static/img/nodata.png" mode=""></image>
			</view>
			<div class="nomore" v-if="!hasMore">没有更多了</div>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[
// 					{
// 						title:'新店开业，全场9折优惠',
// 						time:'2019-01-01'
// 					}
				],
				pageNum:1,
				pageSize:20,
				hasMore:true,
			};
		},
		methods:{
			toView(item){
				uni.navigateTo({
					url:'activityDetail/activityDetail?id='+item.id
				})
			},
			getActivity(flag){
				let that = this
				uni.request({
					url: this.httpUrl + 'activity/list4Page',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						pageNum: that.pageNum,
						pageSize: that.pageSize
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == 1) {
							if(flag){
								that.list = res.data.data.data
							}else{
								that.list.push(...res.data.data.data)
								if(res.data.data.data.length < 10){
									that.hasMore = false
								}else{
									that.hasMore = true
									that.pageNum ++
								}
							}
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								mask: true
							})
						}
					}
				})
			}
		},
		onReachBottom(){
		  if(this.hasMore){
			  this.getActivity(false)
		  }
		},
		onPullDownRefresh() {
			this.getActivity(true)
			uni.stopPullDownRefresh();
		},
		mounted() {
			this.getActivity(false)
		}
	}
</script>

<style>
.activity{
	padding-right: 30px;
}
.time{
	padding-right: 24upx;
}
</style>
